If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > If then

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-19-04, 10:26
carlbj carlbj is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
If then

Hello everyone,

I have a simple question for you. If a column contains certain information I would like to move it to a different column.

I know it can be done in VBA but I'm just not sure how. I've tried but failed. I need some direction from the masters.

For example if column A contains "***" move it to column B.


Thank you very much
Carl
Reply With Quote
  #2 (permalink)  
Old 08-19-04, 10:49
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
something like

Code:
Sub test()
Dim Lastrow As Long
Dim i As Integer

    Lastrow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To Lastrow
        If Range("A" & i).Formula = "***" Then
            Range("B" & i).Formula = "***"
            Range("A" & i).Formula = ""
        End If
    Next i
End Sub
or do you want to insert a cell
Code:
Sub test2()
Dim Lastrow As Long
Dim i As Integer

    Lastrow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To Lastrow
        If Range("A" & i).Formula = "***" Then
            Range("A" & i).Insert xlShiftToRight
        End If
    Next i
End Sub
HTH

Dave
Reply With Quote
  #3 (permalink)  
Old 08-19-04, 11:56
carlbj carlbj is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
Thank you Dave for your quick reply. I may have miscommunicated my problem . Instead of the column I ment to say the cell.

For instance

I want to move the cells that have * before them to another cell in another column. All the other cells in the column can be left alone.

Thanks again,
Carl

I've included a sceen shot of what I'm talking about[IMG]c:/excel.bmp[/IMG]
Attached Images
File Type: bmp excel.bmp (1.37 MB, 63 views)
Reply With Quote
  #4 (permalink)  
Old 08-27-04, 11:31
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
ok sorry about the delay
Code:
Sub test2()
Dim Lastrow As Long
Dim i As Integer

    Lastrow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To Lastrow
        If Left(Trim(Range("A" & i).Formula, 1) = "*" Then
            Range("A" & i).Insert xlShiftToRight
        End If
    Next i
End Sub
HTH

Dave
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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