如何通过VBA将另一个工作表的动态范围引用到活动工作表单元格

时间:2018-08-14 11:38:33

标签: excel vba excel-vba excel-formula

我在公式中没有获得动态范围工作表名称。有人可以协助吗?我在公式中得到的有效工作表范围为=COUNTIF(I3:I31,A3)

Sub Test_DaySumm()

Dim Rg As Range
wksMain.Select
Dim ws1 As Worksheet
Set ws1 = wksMain

If ws1.FilterMode = True Then ws1.ShowAllData
LastRow = ws1.Cells(Rows.Count, "I").End(xlUp).Row
Set MyRange = ws1.Range(Cells(3, 9), Cells(LastRow, 9))

wksDaySummary.Select
xRow = 3
Do Until wksDaySummary.Cells(xRow, 1) = ""
    Set Rg = wksDaySummary.Cells(xRow, 2)
    Rg.Formula = "=COUNTIF( " & MyRange.Address(0, 0) & "," & Rg.Offset(0, -1).Address(0, 0) & ")"
    Rg.Value = Rg.Value
    xRow = xRow + 1
DoEvents
Loop

End Sub

1 个答案:

答案 0 :(得分:6)

看看Range.Address Property纪录片

Program terminated with signal SIGSEGV, Segmentation fault.
#0  gcoHARDWARE_QuerySamplerBase (Hardware=0x22193dc, Hardware@entry=0x0, 
VertexCount=0x7ef95370, VertexCount@entry=0x7ef95368, VertexBase=0x40000,
FragmentCount=FragmentCount@entry=0x2217814, FragmentBase=0x0) at 
gc_hal_user_hardware_query.c:6020
6020    gc_hal_user_hardware_query.c: No such file or directory.
[Current thread is 1 (Thread 0x76feb010 (LWP 697))]
(gdb) bt
#0  gcoHARDWARE_QuerySamplerBase (Hardware=0x22193dc, Hardware@entry=0x0, 
VertexCount=0x7ef95370, VertexCount@entry=0x7ef95368, VertexBase=0x40000,
FragmentCount=FragmentCount@entry=0x2217814, FragmentBase=0x0) at 
gc_hal_user_hardware_query.c:6020
#1  0x765d20e8 in gcoHAL_QuerySamplerBase (Hal=<optimized out>, 
VertexCount=VertexCount@entry=0x7ef95368, VertexBase=<optimized out>, 
FragmentCount=FragmentCount@entry=0x2217814,
FragmentBase=0x0) at gc_hal_user_query.c:692
#2  0x681e31ec in gcChipRecompileEvaluateKeyStates (chipCtx=0x0, 
gc=0x7ef95380) at src/chip/gc_chip_state.c:2115
#3  gcChipValidateRecompileState (gc=0x7ef95380, gc@entry=0x21bd96c, 
chipCtx=0x0, chipCtx@entry=0x2217814) at src/chip/gc_chip_state.c:2634
#4  0x681c6da8 in __glChipDrawValidateState (gc=0x21bd96c) at 
src/chip/gc_chip_draw.c:5217
#5  0x68195688 in __glDrawValidateState (gc=0x21bd96c) at 
src/glcore/gc_es_draw.c:585
#6  __glDrawPrimitive (gc=0x21bd96c, mode=<optimized out>) at 
src/glcore/gc_es_draw.c:943
#7  0x68171048 in glDrawArrays (mode=4, first=6, count=6) at 
src/glcore/gc_es_api.c:399
#8  0x76c9ac72 in CEGUI::OpenGL3GeometryBuffer::draw() const () from 
/usr/lib/libCEGUIOpenGLRenderer-0.so.2
#9  0x76dd1aee in CEGUI::RenderQueue::draw() const () from 
/usr/lib/libCEGUIBase-0.so.2
#10 0x76e317d8 in CEGUI::RenderingSurface::draw(CEGUI::RenderQueue const&, 
CEGUI::RenderQueueEventArgs&) () from /usr/lib/libCEGUIBase-0.so.2
#11 0x76e31838 in CEGUI::RenderingSurface::drawContent() () from 
/usr/lib/libCEGUIBase-0.so.2
#12 0x76e36d30 in CEGUI::GUIContext::drawContent() () from 
/usr/lib/libCEGUIBase-0.so.2
#13 0x76e31710 in CEGUI::RenderingSurface::draw() () from 
/usr/lib/libCEGUIBase-0.so.2
#14 0x001bf79c in tengri::gui::cegui::System::Impl::draw (this=0x2374f08) at 
codebase/src/gui/cegui/system.cpp:107
#15 tengri::gui::cegui::System::draw (this=this@entry=0x2374e74) at 
codebase/src/gui/cegui/system.cpp:212
#16 0x000b151e in falcon::osd::view::MainWindowBase::Impl::preNativeUpdate 
(this=0x2374e10) at codebase/src/osd/view/MainWindow.cpp:51
#17 falcon::osd::view::MainWindowBase::preNativeUpdate 
(this=this@entry=0x209fe30) at codebase/src/osd/view/MainWindow.cpp:91
#18 0x000c4686 in falcon::osd::view::FBMainWindow::update (this=0x209fe00) 
at 
codebase/include/falcon/osd/view/FBMainWindow.h:56
#19 falcon::osd::view::App::Impl::execute (this=0x209fdb0) at 
codebase/src/osd/view/app_view_osd_falcon.cpp:139
#20 falcon::osd::view::App::execute (this=<optimized out>) at 
codebase/src/osd/view/app_view_osd_falcon.cpp:176
#21 0x000475f6 in falcon::osd::App::execute (this=this@entry=0x7ef95c84) at 
codebase/src/osd/app_osd_falcon.cpp:75
#22 0x00047598 in main () at codebase/src/main.cpp:5
(gdb) Quit

并使用.Address(RowAbsolute, ColumnAbsolute, ReferenceStyle, External, RelativeTo) 参数也获取地址中的工作表名称:

External:=True

因此,结果不会像MyRange.Address(RowAbsolute:=False, ColumnAbsolute:=False, External:=True) 那样I3:I31