ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to clear rows before copying data (https://www.excelbanter.com/excel-programming/427053-how-clear-rows-before-copying-data.html)

steve1040

How to clear rows before copying data
 
I have modified the following macro which I got from another posting.

2 questions
1. How do I clear all the data in UpdateListing starting at row 2?

2. In column A of UpdateListing I want the word "UPDATE" for each row.
Is it possible to add the word to V (the Array)?
I tried Array("UPDATE",3, 4, 5) but got an error


Public Sub createupdatelist()
Dim v As Variant, col As Long
v = Array(3, 4, 5) ' D, E, F
col = 2
Set rng = Range(Cells(2, 1), Cells(Rows.Count, 1).End(xlUp))
For i = LBound(v) To UBound(v)
rng.Offset(, v(i)).Copy Destination:= _
Worksheets("UpdateListing").Cells(2, col)

col = col + 1
Next
End Sub


Thanks
Steve

Jacob Skaria

How to clear rows before copying data
 
Use the below for clearing a range and updating cells

Range("A1:B10").Clear
Range("A1:B10") = "Update"

If this post helps click Yes
---------------
Jacob Skaria


"steve1040" wrote:

I have modified the following macro which I got from another posting.

2 questions
1. How do I clear all the data in UpdateListing starting at row 2?

2. In column A of UpdateListing I want the word "UPDATE" for each row.
Is it possible to add the word to V (the Array)?
I tried Array("UPDATE",3, 4, 5) but got an error


Public Sub createupdatelist()
Dim v As Variant, col As Long
v = Array(3, 4, 5) ' D, E, F
col = 2
Set rng = Range(Cells(2, 1), Cells(Rows.Count, 1).End(xlUp))
For i = LBound(v) To UBound(v)
rng.Offset(, v(i)).Copy Destination:= _
Worksheets("UpdateListing").Cells(2, col)

col = col + 1
Next
End Sub


Thanks
Steve



All times are GMT +1. The time now is 10:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com