View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default Macro to copy from one sheet to another and trim data

Hi,
This should get you started. I assume data to be copied is in column
A, starting row 1. If not, change "A" to appropriate column and change in 1
in "for r=1 .." to correct value. In addition, I assumed column B (to be
cleared) was on first worksheet.

HTH

Sub Copy4()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lastrow As Long
Dim r As Long, rr As Long

Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
rr = 4
With ws1
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For r = 1 To lastrow
ws2.Cells(rr, "D") = Left(.Cells(r, "A"), 4)
rr = rr + 1
Next r
' Clear column B starting at B4 ....
.Range("b4:b" & .Cells(Rows.Count, "B").End(xlUp).Row).ClearContents
End With


End Sub

" wrote:

I have worksheet 1 that has some data in a column. I want to copy this
data in to another worksheet 2 that starts on column 4, row 5, but only
the first 4 characters of the data should be put in this cell....and
then I want to have it run in a loop so that it copies the entire
column from worksheet 1 to worksheet 2 in that same fashion (same
column, but increments the row)....How do I do that? Also, how do I
clear out a range of data that starts at B4 and then goes down the
column?

Any help would be appreciated!!! I'm pretty new to excel macro writing