Excel VBA - Loop through column one at a time -


i trying loop through each row in sht1 (b2:b138), , set "input" cell sht2 (a1) each item in loop, 1 @ time. then, value in "output" cell sht2 (n7) copied sht1 (c2:c138).


so example:

sht2 (a1) = value in sht1 (b2), sht1 (c2) = value in sht2 (n7)

repeat

sht2 (a1) = value in sht1 (b3), sht1 (c3) = value in sht2 (n7)


over , on until reaches bottom of list. may have expand list in sht1 colb , have been trying have evaluate number of iterations needed dynamically.

the code i'm trying below gives me correct "outputs" not end in correct cell in sht2 colc. please see below. researched , found this q/a helpful , used influence code. appreciate in advance. my workbook in case need see it.

sub fndesccalc() 'define objects  dim wb workbook dim framework worksheet dim sumframework worksheet dim colb long dim colc long dim lastcolc integer dim lastcolb long  'set variables set wb = thisworkbook set framework = wb.sheets("framework") set sumframework = wb.sheets("sum_framework")  lastrowcb = framework.range("b:b").find("*", searchdirection:=xlprevious).row colb = 2  lastcolc = 138  'this beginning of main loop colc = 2 lastcolc  'this beginning of nested loop     colb = 2 lastcolb     sumframework.range("a1") = framework.range("b" & colb).value     colb = colb + 1  framework.range("c" & colc) = sumframework.range("n7").value colc = colc + 1  next colb  next colc  end sub 

the explanation , code provided don't match. understood want following:

you enter 2 values. search-value (sumframework.range("a1")) , input-value (sumframework.range("n7")). every item in list in column b of sheet "framework" matches search-value gets assigned input-value in column c. if wrong in understanding please elaborate :)

1. in code lastcolb never gets initialized 0 , loop never execute.

2. need 1 loop [edit: described in comment]:

maxrow = framework.range("b:b").find("*", searchdirection:=xlprevious).row 'alternative if last row actual last row , .row < 1000: 'maxrow = framework.range("b1000").end(xlup).row   rowb = 2 maxrow     sumframework.range("a1") = framework.range("b" & rowb).value     framework.range("c" & rowb) = sumframework.range("n7").value next rowb 
  1. "for...next" counts automatically up. colb = colb + 1 skip every section row.

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -