Copy Paste VBA

PivotIdiot

Board Regular
Joined
Jul 8, 2010
Messages
76
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Struggling with some simple code - cant seem to get it right....

VBA Code:
Sub Macro1()
' Macro1 Macro
' Keyboard Shortcut: Ctrl+Shift+M
'
    ActiveCell.Select
    Selection.Copy
    Range(Selection.End(xlDown), Offset(-1)).Select
    ActiveSheet.Paste
    Selection.End(xlDown).Select
End Sub

Im trying copy the contents of the current cell into all the empty cells below, then go to the new cell to repeat.
For example.....
Book1.xlsm
VW
1362DRN90SR6
1363DRN90SR6
1364DRN90SR6
1365DRN90SR6
1366DRN80MK4
1367DRN80MK4
1368DRN80MK4
1369DRN80MK4
1370DRN90SR6
1371DRN
1372DRN
1373DRN
1374DRN
1375DRN80MK4
1376DRN
1377DRN
1378DRN
1379DRN
1380DRN
1381DRN
1382DRN
1383DRN
1384DRN
1385DRN
1386DRN
1387DRN
1388DRN
1389DRN
1390DRN
1391DRN
1392DRN
1393DRN80MK4
1394DRN
1395DRN
1396DRN
1397DRN
Table 1


Any help appreciated
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Are you trying to fill down the values in col W ?
 
Upvote 0
Hi,

Please check below code:

VBA Code:
Sub copyData()
Dim lastRow As Integer, rowno As Integer
Dim pasteRow As Integer
lastRow = WorksheetFunction.CountA(Worksheets("Sheet2").Range("A:A"))

For rowno = 2 To lastRow
    Sheets("Sheet2").Range("B" & rowno).Copy
    For pasteRow = rowno + 1 To lastRow
        If Sheets("Sheet2").Range("B" & pasteRow) = vbNullString Then
            Sheets("Sheet2").Range("B" & pasteRow).Select
            Sheets("Sheet2").Paste
        Else
            rowno = pasteRow - 1
            Exit For
        End If
    Next
    
Next
End Sub
 
Upvote 0
If you are just trying to fill down the values, how about
VBA Code:
Sub PivotIdiot()
   With Range("W1362:W" & Range("V" & Rows.Count).End(xlUp))
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
End Sub
 
Upvote 0
In that case see post#4. ;)
 
Upvote 0
If you are just trying to fill down the values, how about
VBA Code:
Sub PivotIdiot()
   With Range("W1362:W" & Range("V" & Rows.Count).End(xlUp))
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
End Sub
This isnt working how id like.

if i select W1370 and copy it, then select the empty cells below (Range W1370:W1374), paste the contents "90SR6", then move to the next cell to paste W1375.

I dont understand how your code works and how i should make it work, sorry?
 
Upvote 0
In what way didn't it work?
 
Upvote 0
In what way didn't it work?
It error'd.

1610816688293.png
1610816725404.png


This has worked though....
VBA Code:
Sub FillColBlanks_Offset()
'by Rick Rothstein  2009-10-24
'fill blank cells in column with value above
'https://www.contextures.com/xldataentry02.html

  Dim Area As Range, LastRow As Long
  On Error Resume Next
  LastRow = Cells.Find(What:="*", SearchOrder:=xlRows, _
               SearchDirection:=xlPrevious, _
               LookIn:=xlFormulas).Row
  For Each Area In ActiveCell.EntireColumn(1).Resize(LastRow). _
               SpecialCells(xlCellTypeBlanks).Areas
    Area.Value = Area(1).Offset(-1).Value
  Next
End Sub
 
Upvote 0
Oops, it should have been
Rich (BB code):
   With Range("W1362:W" & Range("V" & Rows.Count).End(xlUp).Row)
Or if you want it to work on the entire column
VBA Code:
   With Range("W2:W" & Range("V" & Rows.Count).End(xlUp).Row)
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

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