简体   繁体   中英

Excel - VBA | Parse range values and copy to another column

I'm experiencing a lot of issues with this.

What I'm trying to do is basically get Excel to parse a range cell's contents and if the content doesn't equal "OWNED", copy it to another column. I actually have no idea what to do, been experimenting with different macros I found around the internet but none of them seemed to apply for what I need and I lack the knowledge to get this done, so I would appreciate if someone lent me a hand or at least pointed me in the right direction.

So basically I'm trying to get from this

在此处输入图片说明

to this

在此处输入图片说明

and as you can see, I would need the program to not spare empty cells on the first column.

I will be very grateful to someone who can lend me a hand on this, it's been making me crazy for weeks :/

Thanks in advance.

EDIT: ADDED CODE

Sub Update()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook
Set ws = wb.Sheets("Hoja1")

Dim UninstalledColumn As String
Dim UninstalledRow As Integer

UninstalledColumn = "A"
UninstalledRow = 3

Dim UninstalledCell As Range
Set UninstalledCell = UninstalledColumn & Str(UninstalledRow)

Dim WorkstationList As Range
Set WorkstationList = Range("C3:C12")



End Sub

Try this

Sub Update()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook
Set ws = wb.Sheets("Hoja1")

Dim UninstalledColumn As String
Dim UninstalledRow As Integer

UninstalledColumn = "A"
UninstalledRow = 3

'this is how you would assign a range, but you don't need that.
' Dim UninstalledCell As Range
' Set UninstalledCell = ws.Range(UninstalledColumn & UninstalledRow)

Dim WorkstationList As Range
Set WorkstationList = ws.Range("C3:C12")

For Each cel In WorkstationList
    If cel.Value <> "owned" Then
        ws.Cells(UninstalledRow, UninstalledColumn) = cel.Value
        UninstalledRow = UninstalledRow + 1
    End If
Next cel
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM