简体   繁体   English

Excel-VBA | 解析范围值并复制到另一列

[英]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. 我想做的基本上是让Excel解析范围单元格的内容,如果内容不等于“ OWNED”,请将其复制到另一列。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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