copy down info

muzzy

Active Member
Joined
Apr 8, 2014
Messages
333
I have a vb that I got it work in other workbook and sheet. But I am trying to use it on a new worksheet and it will not work. Can some help me with it or give me a formulas that will do the same thing.

Code:
Sub copy()
Dim varData As Variant
Dim i As Long

varData = Sheet1.Range("C2:C4000") '// Read in the data.

For i = LBound(varData, 1) + 2 To UBound(varData, 1)
    If IsEmpty(varData(i, 1)) Then
        '// Cell is empty. Copy value from above.
        varData(i, 1) = varData(i - 1, 1)
    End If
Next i

'// Write result to sheet.
Sheet1.Range("B2").Resize(UBound(varData, 1) - LBound(varData, 1) + 1, 1) _
    = varData
End Sub
 
The two columns are B and C
I am trying to copy cell C1 to B1 and down to it see the next number in column (C) then copy that one down column B.
Hope this help
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
OK, I see. Your posting is what you want it to look like when complete (not before starting).
One question though, how do you know how far to copy the last entry in column C down (since there is nothing else below it)?
Are you looking at another column to see how far the data should go down?
 
Upvote 0
I was messing around with your code in post #5, and noticed a few things:

1. When you changed it, you changed "varData" to start in row 5, but when you wrote out the results in the last step, you started on row 6. This would cause all your data to shift one row down. Is that really your intention?

2. You named your VBA code procedure "copy". You should never used reserved words (names of functions, procedures, etc) as variable or procedure names, as it could cause intended consequences. I recommend using a name like "MyCopy".

3. With those few minor edits, your code in post #5 seems to work. If it does not work for you, where does the code reside?
Did you place it in a Standard Module, or a Sheet Module?
Are you getting errors or unintended results?
If unintended results, exactly what is happening?
 
Upvote 0
70000Runner, Carol - 70000
IdleAutomatic Idle with Sign-on4/3/201410:37:43AM00:02:02
IdleAutomatic/No reason4/3/201412:58:25PM00:03:09
IdleBreak4/3/201405:17:19PM00:10:20
IdleAdmin/offline work4/3/201411:23:01AM00:04:25
IdleAutomatic/No reason4/3/201401:25:26PM00:00:06
IdleAdmin/offline work4/3/201403:36:07PM00:07:28
IdleAutomatic/No reason4/3/201403:36:10PM00:00:01
Sign-offSign out4/3/201403:36:19PM00:00:09
Date Sign-On Duration32:09:57
Total Reporting Period Sign-On Duration:141:57:53
Total Team - 018 Sign-On Duration:38381:38:15
System Totals:Total Sign-On for All Agent Groups:38381:38:15
Filters Applied:Relative Date:Month To YesterdayStart Date:4/1/2014
Thursday, April 17, 2014 11:27:23Page 1 of 1

<tbody>
</tbody>

I am looking at columns B,C,D. I am looking to info of all the diffidence Idle time per agent. So if you look at Column D you will see the end of the report. Column D is the 3rd column in from the left. It is the column with the word Idle in it.
 
Upvote 0
Did you see my post after that (post #13)?
Heed that advice, and answer those questions, if you cannot get it to work.
 
Upvote 0
I changed the name and I changed the starting cell to b5 it still does not copy down I copy over but not down. I mean it copy c5 to b5 but not down.
 
Upvote 0
update I removed (+ 2 ) from the VB. also I have formula in column (C) so I can get the 5 digit number out of the name. when I remove all the formulas under the first 5 digit number and stop at the second 5 digit in column (C) and then run the VB it works up to the second 5 digit number.
 
Upvote 0
I would approach the problem a little differently (just because it is what I am comfortable with) and do it like this:
Code:
Sub MyCopy()


    Dim lastRow As Long
    
'   Find last row in column D with data
    lastRow = Cells(Rows.Count, "D").End(xlUp).Row
    
'   Copy data in column C to column D (assuming starting on row 5)
    Range("C5:C" & lastRow).copy
    Range("B5").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    
'   Select all blank cells in column B
    Range("B5:B" & lastRow).SpecialCells(xlCellTypeBlanks).Select
    Selection.FormulaR1C1 = "=R[-1]C"
    
End Sub
 
Upvote 0
You VB work if there is no formulas in the cell I have formulas in the cells at are in columns (C) so I can get the 5 digit emp ID from the name.

Can we get the VB to read Values not formulas if so your VB will work for what I need it to do.
 
Upvote 0
Do you mean like this?
Code:
Sub MyCopy()


    Dim lastRow As Long
    
'   Find last row in column D with data
    lastRow = Cells(Rows.Count, "D").End(xlUp).Row
    
'   Copy data in column C to column D (assuming starting on row 5)
    Range("C5:C" & lastRow).copy
    Range("B5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    
'   Select all blank cells in column B
    Range("B5:B" & lastRow).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    Range("B5:B" & lastRow).copy
    Range("B5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,057
Messages
6,128,524
Members
449,456
Latest member
SammMcCandless

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