简体   繁体   English

如何从 vba 中的另一个工作表中获取两个单元格引用

[英]How to take two cell reference from another sheet in vba

I am not able to take the reference from column AB and AC given in sheet ("UPDATER") to sheet("Historical_vol"), can anyone please confirm what am i doing wrong here?我无法将工作表(“UPDATER”)中给出的 AB 和 AC 列引用到工作表(“Historical_vol”),任何人都可以确认我在这里做错了什么吗?

Sub historical_vol()
Application.ScreenUpdating = True
'This will help to watch the status bar update
Application.Calculation = xlCalculationManual
Dim wb As Workbook, uPd As Worksheet, hV As Worksheet
Dim lr As Long, cl As Range
Set wb = ThisWorkbook
Set uPd = wb.Sheets("UPDATER")
Set hV = wb.Sheets("Historical_vol")
uPd.Activate
uPd.Range("AD4:AG4", Range("AD4").End(xlDown)).Clear
lr = uPd.Cells(Rows.Count, "AB").End(xlUp).Row
i = 0
For i = 4 To lr
hV.Range("A9:B9").Value = uPd.Range("AB" & i & ":AC" & i).Value
hV.Calculate
DoEvents
uPd.Range("AD" & i & ":AG" & i).Value = hV.Range("C9:F9").Value
Application.StatusBar = i - 3 & " / " & lr - 3
'View on status bar number of records completed out of total records (lr-3)
Next i
Application.Calculation = xlCalculationAutomatic
End Sub

UPDATER SHEET更新表

在此处输入图像描述

HISTORICAL_VOL SHEET HISTORICAL_VOL 表

在此处输入图像描述

Try changing the line换线试试

For Each cl In uPd.Range("AB4:AC4" & lr)

to

For Each cl In uPd.Range("AB4:AC" & lr).Rows

and the line和线

cl.Offset(0, 2).Resize(1, 4).Value = hV.Range("C9:F9").Value

to

cl.Offset(0, 2).Resize(1, 3).Value = hV.Range("C9:F9").Value

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

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