如何复制VBA中 listbox的内容到excel 工作表中啊?各位谢谢帮哈忙!
答案:2 悬赏:60 手机版
解决时间 2021-03-12 06:50
- 提问者网友:抽煙菂渘情少年
- 2021-03-11 16:50
如何复制VBA中 listbox的内容到excel 工作表中啊?各位谢谢帮哈忙!
最佳答案
- 五星知识达人网友:夜余生
- 2021-03-11 17:29
listbox的内容用value可以取到的,然后excel用sheet定位,用等号就可以了 自己到csdn看看,非常简单的
全部回答
- 1楼网友:执傲
- 2021-03-11 18:06
可以发私信给我,直接建个工程文件给你
option explicit
'得到c列单元格不为空的最大行
private function maxcol(c as long) as integer
dim r as long
for r = 1 to 65536
if cells(r, c).text = "" then
exit for
end if
next r
maxcol = r - 1
end function
private sub setlistbox2items(c as long)
dim r as long, rn as long
listbox2.clear
rn = maxcol(c)
for r = 2 to rn
listbox2.additem cells(r, c)
next r
end sub
private sub commandbutton1_click()
dim ast as string
if listbox1.listindex < 0 then
msgbox ("无选中的父项!")
exit sub
end if
ast = inputbox("输入要增加的内容:")
if ast <> "" then
cells(listbox2.listcount + 2, listbox1.listindex + 1) = ast
call setlistbox2items(listbox1.listindex + 1)
end if
end sub
private sub commandbutton2_click()
dim ast as string
if listbox2.listindex < 0 then
msgbox ("请先选中要修改的子项!")
exit sub
end if
ast = inputbox("本项原内容为:" _
& cells(listbox2.listindex + 2, listbox1.listindex + 1) _
& vbcrlf & "将修改后内容输入下面的文本框:")
if ast <> "" then
cells(listbox2.listindex + 2, listbox1.listindex + 1) = ast
call setlistbox2items(listbox1.listindex + 1)
end if
end sub
private sub commandbutton3_click()
if listbox2.listindex < 0 then
msgbox ("请先选中要删除的子项!")
exit sub
end if
if msgbox("本项内容为:" _
& cells(listbox2.listindex + 2, listbox1.listindex + 1) _
& vbcrlf & "是否确认删除?", vbokcancel, "删除子项") = vbok then
cells(listbox2.listindex + 2, listbox1.listindex + 1).delete 2
call setlistbox2items(listbox1.listindex + 1)
end if
end sub
private sub listbox1_click()
call setlistbox2items(listbox1.listindex + 1)
end sub
private sub userform_activate()
dim r as integer, c as integer
listbox1.clear
for c = 1 to 10
listbox1.additem cells(1, c)
next c
end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯