0% found this document useful (0 votes)
4 views2 pages

Code 3

The document contains a VBA script that processes Excel worksheets by disabling screen updating and alerts. It identifies specific columns for 'CODE', 'CURRENCY', and 'VAR', removes rows with error values in the 'Variable' column, renames the 'CURRENCY' column to 'ID', and generates IDs from the 'CODE' column by extracting text before parentheses. The script iterates through each worksheet in the workbook to apply these transformations.

Uploaded by

uyensakurachan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Code 3

The document contains a VBA script that processes Excel worksheets by disabling screen updating and alerts. It identifies specific columns for 'CODE', 'CURRENCY', and 'VAR', removes rows with error values in the 'Variable' column, renames the 'CURRENCY' column to 'ID', and generates IDs from the 'CODE' column by extracting text before parentheses. The script iterates through each worksheet in the workbook to apply these transformations.

Uploaded by

uyensakurachan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Application.

ScreenUpdating = False
Application.DisplayAlerts = False

For Each ws In wb.Worksheets


With ws
lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

' Tìm vị trí các cột


varCol = 0: codeCol = 0: currCol = 0
Dim c As Long
For c = 1 To lastCol
Select Case UCase(Trim(.Cells(1, c).Value))
Case "CODE": codeCol = c
Case "CURRENCY": currCol = c
End Select
If UCase(Left(.Cells(1, c).Value, 3)) = "VAR" Then varCol = c
Next c

If varCol = 0 Or codeCol = 0 Or currCol = 0 Then GoTo NextSheet

' Xóa dòng có giá trị lỗi trong cột Variable


For r = lastRow To 2 Step -1
v = UCase(Trim(.Cells(r, varCol).Value & ""))
If v = "" _
Or InStr(v, "NA") > 0 _
Or InStr(v, "INVALID CODE OR EXPRESSION ENTERED") > 0 _
Or InStr(v, "NO DATA AVAILABLE") > 0 _
Or InStr(v, "NO WORLDSCOPE DATA FOR THIS CODE") > 0 _
Or InStr(v, "$$ER: E100") > 0 Then
.Rows(r).Delete
End If
Next r

' Đổi tên cột CURRENCY → ID


.Cells(1, currCol).Value = "ID"

' Tạo ID từ CODE (lấy phần trước dấu ngoặc)


lastRow = .Cells(.Rows.Count, codeCol).End(xlUp).Row
For r = 2 To lastRow
v = .Cells(r, codeCol).Value & ""
pos = InStr(v, "(")
If pos > 0 Then
.Cells(r, currCol).Value = Left(v, pos - 1)
Else
.Cells(r, currCol).Value = v
End If
Next r
End With

You might also like