PDA

View Full Version : Solved: Inserting cell value in formula



winstonhuxle
07-12-2013, 06:26 AM
Hey guys,

I'm having problem with inserting a value of cell in formula
for example:
Rows("12:value of A3 cell").Select Selection.Delete

i've tried .range, .value but still problems with separator. Any idea?

Thanks so much

Kenneth Hobs
07-12-2013, 07:04 AM
Welcome to the forum!

Range("A1").Value2 = 11
Rows("10:" & Range("A1").Value2).Delete

winstonhuxle
07-12-2013, 07:27 AM
Thanks Kenneth, however i forgot to mentioned that this cell, from which i need value is in different WB. Is it possible to connect it anyway?

Kenneth Hobs
07-12-2013, 08:29 AM
For that scenario, I would use:
Sub t()
MsgBox GetValue("x:\test", "test.xlsx", "Sheet1", "A1")
End Sub

'=GetValue("c:\files", "budget.xls", "Sheet1", "A1")
Private Function GetValue(path, file, sheet, ref)
' path = "d:\files"
' file = "budget.xls"
' sheet = "Sheet1"
' ref = "A1:R30"

Dim arg As String

If Right(path, 1) <> "\" Then path = path & "\"

If Dir(path & file) = "" Then
GetValue = "file not found"
Exit Function
End If

arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("a1").Address(, , xlR1C1)

GetValue = ExecuteExcel4Macro(arg)
End Function

snb
07-13-2013, 06:11 AM
Sub M_snb()
Rows("12:" & getobject("G:\OF\otherworkbook.xlsx").sheets(1).cells(3,1).value).Delete
End Sub

mikerickson
07-13-2013, 11:53 AM
Perhaps this would be of help.
http://www.vbaexpress.com/forum/showthread.php?t=19661

Removing the "\" from the linked sub should get you where you want.

Edit: See post#10 for removing the "\"

winstonhuxle
07-14-2013, 03:24 AM
Thank you all. I used code of snb, it works perfectly:)