Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.excel.programming > #109102
| From | isabelle <i@v.invalid> |
|---|---|
| Newsgroups | microsoft.public.excel.programming |
| Subject | Re: VBA - How to "execute" a dynamic variable assignment |
| Date | 2016-07-19 21:34 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nmmkfp$18tn$1@gioia.aioe.org> (permalink) |
| References | <dc55f9c2-b117-48f4-a0a8-952f24451f97@googlegroups.com> |
hi,
with
Cell A1: "MyVar"
Cell A2: "Purple"
Cell A3: "String"
copy the following code in the Module1, and run macro ModifyCode
Sub test1()
End Sub
Sub ModifyCode()
Dim code(1)
Dim Mdl As String, MyMacro As String
Mdl = "Module1"
MyMacro = "test1"
code(0) = "Dim " & [A1] & " as " & [A3]
code(1) = "msgbox [A2]"
For i = 0 To 1
s = s & code(i) & Chr(10)
Next
With ThisWorkbook.VBProject.VBComponents(Mdl).codemodule
.InsertLines .ProcStartLine(MyMacro, 0) + 1, s
End With
test1
With ThisWorkbook.VBProject.VBComponents("Module1").codemodule
.DeleteLines .ProcStartLine("ModifyCode", 0), .ProcCountLines("ModifyCode", 0)
End With
End Sub
isabelle
Le 2016-07-18 à 18:14, ddmcmath@gmail.com a écrit :
>
> Cell A1: "MyVar"
> Cell A2: "Purple"
> Cell A3: "String"
>
>
> I want to run code that does the following
>
> Public MyVar as String
> MyVar = "Purple"
>
> How would I do that?
>
> it's kinda like
>
> Execute "Dim " & range(A1) & " as " & range(A3)
> Execute range(A1) & " = '" & range(A2) & "'"
>
> Is there a way?
>
Back to microsoft.public.excel.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
VBA - How to "execute" a dynamic variable assignment ddmcmath@gmail.com - 2016-07-18 15:14 -0700
Re: VBA - How to "execute" a dynamic variable assignment GS <gs@v.invalid> - 2016-07-19 00:55 -0400
Re: VBA - How to "execute" a dynamic variable assignment "Auric__" <not.my.real@email.address> - 2016-07-19 08:20 +0000
Re: VBA - How to "execute" a dynamic variable assignment GS <gs@v.invalid> - 2016-07-19 13:09 -0400
Re: VBA - How to "execute" a dynamic variable assignment "Auric__" <not.my.real@email.address> - 2016-07-20 00:57 +0000
Re: VBA - How to "execute" a dynamic variable assignment GS <gs@v.invalid> - 2016-07-20 12:29 -0400
Re: VBA - How to "execute" a dynamic variable assignment isabelle <i@v.invalid> - 2016-07-19 21:34 -0400
Re: VBA - How to "execute" a dynamic variable assignment isabelle <i@v.invalid> - 2016-07-19 21:47 -0400
csiph-web