Copy cells from 1 sheet to another in a loop using a different starting and ending position

Learner99

New Member
Joined
Apr 7, 2014
Messages
21
Hi could you please help me with this loop.

I’m trying to copy all cells from my current sheet starting at “B9” down.
To a New sheet Starting at cell “A34”

I marked out the 2 areas where I’m stuck.

Thanks

Code:
    Range("B9").Select  ‘ starting point
    Dim x As Variant
    Dim Icount As Integer
  
    
    For Each x In Range("B9", Range("B9").End(xlDown))   'For Loop searches column for a blank
    If x = "" Then Exit For                              'Ends the loop when it hits a blank
   
    vpart2 = Range("B" & Icount).Value   ‘*******ß---Need Help Here
    vcomplete = "SET datafile=" & Chr(34) & vpart1 & vpart2 & ".dat" & Chr(34)
    Sheets("Output").Range("A" & Icount).Value = vcomplete     ‘*******ß---Need Help Here
   
    Icount = Icount + 1
    Next
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
It looks like you are trying to reference a cell with the lines you need help with.

Try using the Cells(rowIndex, colIndex) call.

Like this:

Code:
vpart2 = Cells(Icount, "B").Value   '*******ß---Need Help Here
    vcomplete = "SET datafile=" & Chr(34) & vpart1 & vpart2 & ".dat" & Chr(34)
    Sheets("Output").Cells(Icount, "A").Value = vcomplete     '*******ß---Need Help Here
 
Upvote 0
It looks like you are trying to reference a cell with the lines you need help with.

Try using the Cells(rowIndex, colIndex) call.

Like this:

Code:
vpart2 = Cells(Icount, "B").Value   '*******ß---Need Help Here
    vcomplete = "SET datafile=" & Chr(34) & vpart1 & vpart2 & ".dat" & Chr(34)
    Sheets("Output").Cells(Icount, "A").Value = vcomplete     '*******ß---Need Help Here

This makes sense for the start position B9 , but it does not set the start position to copy the data to on the next sheet which needs to be A34
 
Upvote 0
If it just that you could offset it with a "+ 25".

Like this:

Code:
[COLOR=#333333]vpart2 = Cells(Icount, "B").Value   '*******ß---Need Help Here[/COLOR][COLOR=#333333] 
vcomplete = "SET datafile=" & Chr(34) & vpart1 & vpart2 & ".dat" & Chr(34) 
[/COLOR][COLOR=#333333]Sheets("Output").Cells(Icount + 25, "A").Value = vcomplete     '*******ß---Need Help Here

[/COLOR]

Honestly though, you are going through each cell anyway, with the for loop, so you can grab the data using that instead of calling out the cell each time.

Code:
    Range("B9").Select ' starting point
    Dim x As Variant
    Dim Icount As Integer
  
    
    For Each x In Range("B9", Range("B9").End(xlDown))   'For Loop searches column for a blank
    If x = "" Then Exit For                              'Ends the loop when it hits a blank
   
    vpart2 = x.Value   '*******ß---Need Help Here
    vcomplete = "SET datafile=" & Chr(34) & vpart1 & vpart2 & ".dat" & Chr(34)
    
    Sheets("Output").Cells(x.Row, "A").Value = vcomplete     '*******ß---Need Help Here
    
    Next
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top