gpt4 book ai didi

vba - 将 Excel 工作表中的所有单元格作为字符串 (VBA)

转载 作者:行者123 更新时间:2023-12-03 02:14:16 26 4
gpt4 key购买 nike

基本上,我正在创建一个 Excel 应用程序,该应用程序在运行时会提示用户指向特定的 Excel 文件,并且它将将该位置作为字符串,工作正常。我不确定如何做是在事件工作表中选择一个范围并获取每个单元格中的值并将它们组合成 1 个字符串。

这是我到目前为止的代码:

Option Explicit

Sub locate_file()

Dim file As String
Dim sheet1_95 As String
Dim theRange As Range

'prompt user for location of other excel sheet'
file = Application.GetOpenFilename("Excel Files (*.xlsx), *.xlsx")

'test input of location'
Workbooks("testing input file.xlsx").Sheets("location").Activate
Range("A1") = file

'activate the workbook and sheet'
Workbooks("95%.xlsx").Sheets("DT").Activate

'Testing retrieving cells as string'
Set theRange = Range("A2:A4")

'how do i retrieve values in this range and combine them into 1 string?'

End Sub

最佳答案

What I am not sure how to do is choose a range in the active worksheet

通过使用 Application.InputBox 函数(而不是 VBA.InputBox):

dim r as range
set r = application.inputbox("Select a range", Type:=8)
<小时/>

and take the value in each cell and combine them into 1 string.

通过循环单元格:

dim c as range
dim s as string

for each c in r.cells
s = s & c.value
next

关于vba - 将 Excel 工作表中的所有单元格作为字符串 (VBA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6512095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com