I am playing with vbscript and how to make my life easier. Now I want to run a script which opens an excel file. Copy column C (unknown rows - length) to column B and concatenate it to something.
Example:
-------------------
||| A | B | C |
-------------------
|1|ONE | ANY | 11 |
|2|TWO | ANY | 42 |
|3|FOUR| ANY | 96 |
|4|SIX | ANY | 42 |
-------------------
To This:
||| A | B | C |
-------------------
|1|ONE |*11* | 11 |
|2|TWO |*42* | 42 |
|3|FOUR|*96* | 96 |
|4|SIX |*42* | 42 |
-------------------
So far I have tried this:
Option Explicit
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
With objExcel
.Workbooks.Open ("Z:\1\one.xlsx")
.Visible = False
.Range("C:C").Copy
.Range("B1").Select
.ActiveSheet.Paste
.ActiveWorkbook.Close(True)
.Quit
End With
Firstly it gives me an error that clipboard is full and it is better to clean up in order to free memory. And secondly I have not found a concatenate function in internet for vbscript.
With some research and the Help of Bruce that worked for me in case someone is interested:
Option Explicit
Dim objExcel,LastRow
Const xlUp = -4162
Set objExcel = CreateObject("Excel.Application")
With objExcel
.Workbooks.Open ("Z:\1\onest.xlsx")
.Visible = False
LastRow = .Range("A1048576").End(xlUp).Row
.Range("C1:" & "C" & LastRow).Copy
.Range("B1").Select
.ActiveSheet.Paste
Do While LastRow <>0
.Cells(LastRow,2)="*"&.Cells(LastRow,3)&"*"
LastRow = LastRow - 1
Loop
.ActiveWorkbook.Close(True)
.Quit
End With
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.