Increment cell number after blank row and paste it in a range

gsingh4

New Member
Joined
Jun 3, 2016
Messages
10
How can I move further in writing this code so that it skips if a blank row is found and then increment the cell in Sheet2 from G53 to G54 and then paste it in column A after the blank row is found and so on for G53:G60. I could do it manually too but I am just trying to give this a shot.

Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">[COLOR=#101094]Sub[/COLOR][COLOR=#303336] Copy[/COLOR][COLOR=#303336]()[/COLOR][COLOR=#303336]

    Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet2"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"G53"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Copy Destination[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A:A"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
    Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]CutCopyMode [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336]

    [/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]CountA[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]ActiveCell[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]EntireRow[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]0[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336] Skip

    [/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]Sub

[/COLOR]


</code>Thanks for your help.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Why do you need to know if the whole row is empty if you only copy a cell?
don't you want to paste in the next empty cell in column A in Sheet1?
Where did you get this code? Certainly not with the macro recorder
Explain in a concise manner what you want to accomplish
 
Upvote 0
A) because my data is broken down according to weeks. Each week has 40-50 rows of data so the blank row separates one week from another. I tried using one cell empty, it stops right after the first destination cell.
B) The aim is to copy one cell from one sheet and paste its contents to a range of cells separated by a blank line.
C) I did some research and fiddled around to compile the code. It does copy the contents to the given range but doesn't stop when an empty row is found.
D) concisely, I want to copy cell b2 from sheet 1 and paste it to column A in sheet 2 and stop when a blank row is found. Then increment the cell to b3 and copy paste it in column A till the next blank line is found. And so on.

The idea is to assign the weekdates (in sheet2) to the data for each week (sheet1) (50-60rows per week- not consistent)


hope this helps.
 
Upvote 0
Do I understand you right that you have blocks of data separated by a blank (= empty) cell/row?
Just to get clear on all of this, do the following
Open an empty workbook and in Sheet2, Column A, fill in the following:
Cell A1 is a header. Enter anything you want ("hdr col A" maybe?)
Cells A2 to A10: Week 1
Cells A12 to A16: Week 2
Cells A18 to A31: Week 3
Cells A33 to A40: Week 4
Now in Sheet3, Column F enter the following:
F1 = hdr col F, F2 = AAA, F3 = BBB, F4 = CCC, F5 = DDD, F6 = EEE, F7 = FFF
Copy/Paste the following code into a regular module.
Code:
Sub Offset_Values()
    Dim Area As Range, rng As Range, i As Long
    i = 2
    For Each Area In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
        Area.Offset(, 1).Value = Sheets("Sheet3").Cells(i, 6).Value
        i = i + 1
    Next Area
End Sub
Go to Sheet2 and run the macro.
Is the result close to what you want in your real life workbook?
 
Upvote 0
It was quite close to what I wanted. I had to tweak a few things around and the final result was beautiful. Much thanks.
 
Upvote 0
Good to hear that that was what you needed.
Thanks for letting us know.
Good luck
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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