Solved

Copying/Moving data on a worksheet

Posted on 2014-12-23
5
93 Views
Last Modified: 2014-12-23
Hi,

I need a VBA solution to look at Column L and if any row contains the word "NULL", copy the word "NULL" to Column "R" then copy whatever is in Column K to Column L.

Thanks in advance,

swjtx99Example.xlsx
0
Comment
Question by:swjtx99
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:fabriciofonseca
ID: 40515564
Create a Macro and add the code below:

  Dim Myrow As Long
  Myrow = 1
  While Range("L" & Myrow).Value <> ""
    If UCase(Range("L" & Myrow).Value) = "NULL" Then Range("R" & Myrow).Value = "Null"
    Range("L" & Myrow).Value = Range("K" & Myrow).Value
    Myrow = Myrow + 1
  Wend


Regards
0
 
LVL 8

Expert Comment

by:fabriciofonseca
ID: 40515568
Sorry... I forgot to close the "if". Please use the code below:

  Dim Myrow As Long
  Myrow = 1
  While Range("L" & Myrow).Value <> ""
    If UCase(Range("L" & Myrow).Value) = "NULL" Then
        Range("R" & Myrow).Value = "Null"
        Range("L" & Myrow).Value = Range("K" & Myrow).Value
    End If
    Myrow = Myrow + 1
  Wend
0
 

Author Comment

by:swjtx99
ID: 40515668
Hi fabriciofonseca,

Sorry, I just found I have some blanks (empty cells in column L) and the code stops at the first blank. Can this be revised to go from the bottom up or skip any blanks in column L?

Thanks,

swjtx99
0
 
LVL 8

Accepted Solution

by:
fabriciofonseca earned 500 total points
ID: 40515693
Dim Myrow As Long
  For Myrow = 1 To 65536 'you can change the 65536 and decrease / increase for any row quantities you want / need
    If UCase(Range("L" & Myrow).Value) = "NULL" Then
        Range("R" & Myrow).Value = "Null"
        Range("L" & Myrow).Value = Range("K" & Myrow).Value
    End If
  Next Myrow
0
 

Author Closing Comment

by:swjtx99
ID: 40515729
Thanks fabriciofonseca,

Works great!

Regards,

swjtx99
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question