score:6

Accepted answer

welcome to stackoverflow :)

a1 can be written as range("j1").value and d43 can be written as range("k1").value. so "a1:d43" can be written as range("j1").value & ":" & range("k1").value

simply replace range("a1:d43").select with range(range("j1").value & ":" & range("k1").value).select

btw, avoid using the .select. you may want to see how to avoid using select in excel vba

your code can be written as

range(range("j1").value & ":" & range("k1").value).copypicture _
appearance:=xlscreen, format:=xlbitmap

i am assuming that range("j1") and range("k1") are in the same sheet as from where you want to make the selection. if not then fully qualify the cells. for example

sheet1.range(sheet2.range("j1").value & ":" & sheet2.range("k1").value)

change sheet1 and sheet2 as applicable.

as jeeped showed in his post, you can also write the above as

sheet1.range(sheet2.range("j1").value, sheet2.range("k1").value).copypicture _
appearance:=xlscreen, format:=xlbitmap

score:1

try,

sub button3_click()
'
' button3_click macro
'
    range(cells(1, "j").text, cells(1, "k").text).copypicture _
       appearance:=xlscreen, format:=xlbitmap

end sub

score:1

another possibility, using join() function on an array made out of wanted range values:

option explicit

sub button3_click()
'
' button3_click macro
'
    range(join(application.transpose(application.transpose(range("j1:k1").value)), ":")).copypicture _
    appearance:=xlscreen, format:=xlbitmap

end sub

Related Query

More Query from same tag