VBA Question: Move cell contents if...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Need some VBA help to move contents of column G to column C if column C="",
and delete contents column G after move.

Logically:

IF C="" (move G to C then delete G),(do nothing)

Can you help with a macro please?

Thanks,

Scott
 
Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

With Worksheets("sheet1")
Set myRng = .Range("G1", .Cells(.Rows.Count, "G").End(xlUp))

For Each myCell In myRng.Cells
If .Cells(myCell.Row, "C").Value = "" Then
.Cells(myCell.Row, "C").Value = myCell.Value
myCell.Value = ""
End If
Next myCell
End With
End Sub



If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
Try this, works for me

lastrow = Worksheets("Sheet1").UsedRange.Row + Worksheets("Sheet1").UsedRange.
Rows.Count - 1

For a = 1 To lastrow
If Sheet1.Cells(a, 3).Value = "" Then
Range("C" & a).Value = Range("G" & a).Value
Range("G" & a).ClearContents
End If
Next a

Regards

(e-mail address removed)
 
Dave,

Can the "sheet1" be changed to the active worksheet instead? How would I do
that?

Thanks for you help.

Sincerely,

Scott
 
One last question on this topic. How can I change the following from (is
="") to (is not = "")

If .Cells(myCell.Row, "C").Value = ""

Thanks,

Scott
 
If .Cells(myCell.Row, "C").Value = ""
becomes
If .Cells(myCell.Row, "C").Value <> ""



Scott said:
One last question on this topic. How can I change the following from (is
="") to (is not = "")

If .Cells(myCell.Row, "C").Value = ""

Thanks,

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top