Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Macro to copy data

Hi!

Can anybody help me with a macro that checks all empty cells in a column and copies the data from the column beside?
I'll show you an example

A B
1 MYPKG IDJKT
2 ZADUR
3 KRPUS KRICH
4 CNSHA
5 HKHKG


So, I want a macro that checks all empty cells in column A, i.e., A2, A4 and A5, and then copy the data from column B.
In this sense, A2 would have the same as B2.
A4 would have the same as B4
A5 would have the same as B5
and so on, and so on...

Thanks beforehand.

Gustavo.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Macro to copy data

Try this
Sub copyColumB()
Const testCol = "A"
Const copyCol = "B"
Dim MySheet As Worksheet, i As Long
Dim lastrow As Long

Set MySheet = ActiveSheet
lastrow = MySheet.Cells(Rows.Count, testCol).End(xlUp).Row
For i = 1 To lastrow
If MySheet.Range(testCol & i).Value = "" Then
MySheet.Range(testCol & i).Value = MySheet.Range(copyCol & i).Value
End If
Next i
End Sub

"Gustavo Strabeli" wrote:

Hi!

Can anybody help me with a macro that checks all empty cells in a column and copies the data from the column beside?
I'll show you an example

A B
1 MYPKG IDJKT
2 ZADUR
3 KRPUS KRICH
4 CNSHA
5 HKHKG


So, I want a macro that checks all empty cells in column A, i.e., A2, A4 and A5, and then copy the data from column B.
In this sense, A2 would have the same as B2.
A4 would have the same as B4
A5 would have the same as B5
and so on, and so on...

Thanks beforehand.

Gustavo.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Macro to copy data

Try this one also
Sub copyColumB()
Const testCol = "A"
Const copyCol = "B"
Dim MySheet As Worksheet, i As Long
Dim lastrow As Long

Set MySheet = ActiveSheet
lastrow = MySheet.Cells(Rows.Count, copyCol).End(xlUp).Row
For i = 1 To lastrow
If MySheet.Range(testCol & i).Value = "" Then
MySheet.Range(testCol & i).Value = MySheet.Range(copyCol & i).Value
End If
Next i
End Sub

"Gustavo Strabeli" wrote:

Hi!

Can anybody help me with a macro that checks all empty cells in a column and copies the data from the column beside?
I'll show you an example

A B
1 MYPKG IDJKT
2 ZADUR
3 KRPUS KRICH
4 CNSHA
5 HKHKG


So, I want a macro that checks all empty cells in column A, i.e., A2, A4 and A5, and then copy the data from column B.
In this sense, A2 would have the same as B2.
A4 would have the same as B4
A5 would have the same as B5
and so on, and so on...

Thanks beforehand.

Gustavo.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Macro to copy data

Mike,
It's working perfectly.
Thanks a lot for the help.

Regards,
Gustavo.


"Mike" escreveu na mensagem ...
Try this one also
Sub copyColumB()
Const testCol = "A"
Const copyCol = "B"
Dim MySheet As Worksheet, i As Long
Dim lastrow As Long

Set MySheet = ActiveSheet
lastrow = MySheet.Cells(Rows.Count, copyCol).End(xlUp).Row
For i = 1 To lastrow
If MySheet.Range(testCol & i).Value = "" Then
MySheet.Range(testCol & i).Value = MySheet.Range(copyCol & i).Value
End If
Next i
End Sub

"Gustavo Strabeli" wrote:

Hi!

Can anybody help me with a macro that checks all empty cells in a column and copies the data from the column beside?
I'll show you an example

A B
1 MYPKG IDJKT
2 ZADUR
3 KRPUS KRICH
4 CNSHA
5 HKHKG


So, I want a macro that checks all empty cells in column A, i.e., A2, A4 and A5, and then copy the data from column B.
In this sense, A2 would have the same as B2.
A4 would have the same as B4
A5 would have the same as B5
and so on, and so on...

Thanks beforehand.

Gustavo.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to copy data when data is detected in another column(s). Richard Excel Worksheet Functions 2 October 23rd 09 11:46 PM
Macro to copy & paste data Satish Excel Discussion (Misc queries) 3 December 18th 08 04:50 AM
Copy data in a macro. jfaz Excel Discussion (Misc queries) 1 July 13th 07 12:26 PM
Macro Help. Copy data from 1 workbook to another on next available Howeecow Excel Discussion (Misc queries) 0 June 6th 07 08:29 PM
Macro to copy data Sho Excel Programming 4 November 9th 04 04:58 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"