ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[Âà¶K] VBAªº¼g§@§Þ¥©»P¼W¶i®Ä¯à

[Âà¶K] VBAªº¼g§@§Þ¥©»P¼W¶i®Ä¯à

VBAªº¼g§@§Þ¥©»P¼W¶i®Ä¯à

¸g¥Ñ¿ý»s²£¥Íªº¥¨¶°¡A³q±`µ{¦¡½X³£·|§t¦³«Ü¦h Select¡A¬Æ¦Ü©¹«á¦Û¤v¼gªºµ{¦¡¤]²ßºD¥Î¤@°ï Select¡C¼gµ{¦¡ªº¤H¥H¬°¥²¶· Select ¤@­Óª«¥ó«á¤~¯à¹ï¥¦°µ³B²z¡A¦ý³o¬O [¿ý»s¥¨¶°] »~¾Éªº¿ù»~Æ[©À (¦Û¤v¤]¨S¦³¹ý©³¤F¸Ñ»yªk)¡A¦Ó¥B¬O³y¦¨¥¨¶°°õ¦æ®Ä²v¤£¨Îªº­ì¦]¤§¤@¡C

¤@¡B¼Æ¼Æ¬Ý§Aªºµ{¦¡¸Ì¦³¦h¤Ö "Select" ?
°£«Dµ{¦¡´N¬O­n¨Ì¨Ï¥ÎªÌ¿ï¨úªºª«¥ó¨Ó°µ°Ê§@¡A§_«h Select ©M Selection ³£¬O¦h¾lªº.
¡· ¼Ð·Çªºª«¥ó±±¨î»yªk¡G
¡@ ª«¥ó.¤èªk¡@¡]¨Ò¦p Range("A1").Copy¡^
¡@ ª«¥ó.ÄÝ©Ê = ­È¡@¡]¨Ò¦p Range("A1").ColorIndex = 15¡^
¦Ó¤£¬O¤@©w­n¥ý Select ª«¥óµM«á¦A¹ï Selection °µ°Ê§@.

Á|¨Ò¦Ó¨¥¡A§A­n½Æ»s Sheet1.A1 ªº­È¨ì Sheet2.B1 --
¡@Range("A1").Copy
¡@Sheets(2).Select
¡@Range("B1").Select
¡@Range("B1").PasteSpecial xlPasteValues
¨ä¹ê¥i¥H³o»ò¼g --
¡@Sheets(2).Range("B1") = Sheets(1).Range("A1")
¦pªG¤º®e»P®æ¦¡³£­n½Æ»s¡A¥i¥H³o»ò¼g --
¡@Sheets(1).Range("A1").Copy Sheets(2).Range("B1")

¤£­n¬Ý³o¨S¤°»ò¡A§AªºVBAÆ[©À©Mµ{«×¯à§_§ó¶i¤@¨B¡A³o¬O«Ü­«­nªº¤@ÂI¡C

¤G¡BÃö³¬¿Ã¹õ§ó·s ¡]Application.ScreenUpdating¡^
µ{¦¡¸Ì°µªº°Ê§@¶V¦h¡A¿Ã¹õ§ó·sªº°ÝÃD´N¶V©úÅã¡C¨Ò¦p¿ï¨ú¤FÀx¦s®æ¡B¿ï¨úª«¥ó¡B½Æ»s¡B¶K¤W¡B¤Á´«¤u§@ªí... Excel ³£·|§ïÅܵJÂI (Focus). ¨C§ïÅܤ@¦¸¡A´N¬O¤@¦¸¿Ã¹õ§ó·s¡C·Q·Q¬Ý¡A¦b¤@³s¦êªº¿Ã¹õ§ó·s¤§¤¤¡A¤£¦ý¥O¨Ï¥ÎªÌ²´ªá¼º¶Ã¡Aµ{¦¡°õ¦æªº¾ãÅé®Ä¯à¤]·|¤U­°¡C

³o»P´î¤Ö Select ¬O¤@Åé¨â­±ªº¨Æ¡A¨ä¹ê«Ü¦h¿ï¨úÀx¦s®æ¡B¿ï¨úª«¥ó¡B½Æ»s¡B¶K¤W¡B¤Á´«¤u§@ªí... ªº°Ê§@³£¬O¤£¥²­nªº¡C¥u­n§Þ¥©¥Îªº¦n¡AScreenUpdating ´X¥G¥i¥H§ô¤§°ª»Õ¡C

¤T¡B¹L¦h/¤£¥²­nªº°j°é¤]·|­°§C°õ¦æ®Ä²v
°j°é (¦p For...Next¡BDo...Loopµ¥µ¥) ¬O«Ü­«­nªº¼g§@§Þ¥©¤§¤@¡A¥¦¯à¤j´T²¤Æµ{¦¡¤¤­«½Æªº°Ê§@¡A¦Ó¥B¬O¿ý»s¤£¥X¨Óªº¡C
³o¸Ì©Ò¿×¤£¥²­nªº°j°é¬O«ü³B²zªº½d³ò¤Ó¤j¡A®ö¶O¹L¦h®É¶¡¡C¨Ò¦p
For Each cell In Columns(1)
¡@......
Next
For Each cell In [A1:A65536]
¡@......
Next
¥H¤W¨â­Ó°j°é³£¬O³B²z A Äæ 6 ¸U¦h­ÓÀx¦s®æ¡C
»¡¹ê¦bªº¡A³s´X¤d­ÓCell§Ú³£¦³ÂI¾á¤ß¤F¡A¦óªp´X¸U­Ó -- ¦³¥²­n¶Ü??
¦ó¤£§PÂ_¦n¸ê®Æªº½d³ò¦A¨Ó°µ°j°é --
For Each cell In Range([A1], [A65536].End(xlUp))
¡@......
Next

°Ñ¦Ò: ¦p¦ó§PÂ_¸ê®Æ½d³ò
http://gb.twbts.com/index.php/topic,315.0.html
http://gb.twbts.com/index.php/topic,584.0.html

¥|¡BÄÀ©ñª«¥óÅܼƦû¥Îªº°O¾ÐÅéªÅ¶¡
¦b³o¸Ì¤×«ü¹ïÀ³¥Îµ{¦¡(Appliation)ªº¤Þ¥Î»P¦s¨ú¡A¤U¨Ò±qWordªí®æ¨ú¦^¸ê®Æ¦ÜExcel¤u§@ªí --

Sub get_word_table( )
Dim wrdApp As Object
Set wrdApp = CreateObject("Word.Application") '«Ø¥ß¤Þ¥ÎWordÀ³¥Îµ{¦¡ªºª«¥ó
Set wrdDoc = wrdApp.Documents.Open("D:\Temp\ole_test.doc") '¤Þ¥ÎWord¤å¥ó
With wrdDoc.Tables(1)
¡@For r = 1 To .Rows.Count
¡@¡@For c = 1 To .Columns.Count
¡@¡@Cells(r, c) = .Cell(r, c)
¡@¡@Next c
¡@Next r
End With
wrdDoc.Close 'close the document
wrdApp.Quit 'close Word
Set wrdDoc = Nothing 'ÄÀ©ñª«¥óÅܼÆ
Set wrdApp = Nothing
End Sub

ªì¾ÇªÌ±`±`·|©¿²¤³Ì«á¨â¥y¡A¦pªG¤£¼gÁöµM¤£·|¼vÅTµ{¦¡ªº¹B¦æ¡A¦ý±q°O¾ÐÅéºÞ²z©M®Ä¯à±±¨îªº¨¤«×¦Ó¨¥¡A³o¬O­Ó«Ü¤£¦nªº²ßºD¡C

·í¬Ù«h¬Ù¡A¬Ùªº¬O¦h¾l­«½Æªºµ{¦¡½X¡F
·í¥Î«h¥Î¡A¥Îªº¬O¤£¥i©Î¯Êªºµ{¦¡½X¡C

--------------------------------------------------------------------------------

¤j®a»{¬°¦³¤£¨¬©ÎºÃ°Ý¤§³B¡AÅwªï´£¥X¸É¥R©M°Q½×¡C

½Ð°Ýª©¥D
¡@Sheets(2).Range("B1") = Sheets(1).Range("A1")
³oºØ¼gªk¦pªG­n°w¹ï¬Y½d³ò¨Ò¦p±qsheet1ªºA1:a10°µ°}¦CÂà´«¨ìsheet2ªºa1:j1
­n¦p¦ó½s¼gµ{¦¡½X?

TOP

¦^´_ 2# yuch8663


    sheet2.[A1:J1]=application.transpose(sheet1.[A1:A10])
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

­ì¨Ó¬O³o¼Ë¼g¡A©Ó»Xª©¥D«ü¾É¡AÅý§Ú¼W¼s¨£»D¤F¡C

TOP

専¤ß¬Ý¤F¤@¤ù,«Ü¹ê¥Î.
ddlam

TOP

·PÁª©¥Dªº¤À¨É¡AÀò¯q¨}¦h
¸`¬Ù·s¤â«Ü¦hªº®É¶¡¤]°ö¾i¨}¦nªº²ßºD
¥u°µ¦Û¤vÁA¸Ñªº¥«³õ

TOP

¦^´_ 6# kingaaron


    ÁÂÁ¤j¤jªº¥Î¤ß¡A¨ü¯q­ê²L¡A·PÁÂ!

TOP

·PÁªO¥D¤À¨É:
¤@¡B¼Æ¼Æ¬Ý§Aªºµ{¦¡¸Ì¦³¦h¤Ö "Select" ?
select ¯uªº¬O¤£¤j»Ý­n, §Ú¥Ø«e¤w¸g«Ü¤Ö¨Ï¥Î¤F, ¤j³¡¤À¥Î¦b­n¨ú±o¯S©w¦ì§}, ¥H§@¬°¤U¤@­Ó«ü¥O°Ñ¦Ò¤§¥Îo

¤T¡B¹L¦h/¤£¥²­nªº°j°é¤]·|­°§C°õ¦æ®Ä²v
§Ú¥H«e·|¥Î do while or if «ü¥O¨Ó§PÂ_«áÄ~Äò°õ¦æ, «á¨Ó¸I¨ì i=i+1 ®É·|¸I¨ì·¸¦ì°ÝÃD, «á¨Ó´N§ï¥Î find «ü¥O,
§Ú·Pı°õ¦æ³t«×¬O§Ö¤F«Ü¦h, ³o¬O§_¤ñ¸û¦n?
James

TOP

·PÁª©¥D¤À¨É
§Ú­è¶}©l¨Ï¥ÎVBAªº½T¤]¬O§â¿ý»s¨ìªº¥¨¶°·Ó³æ¥þ¦¬
¤£¹L ²{¦b¤w¸g¯à¼g¥X¤ñ¸û¦³®Ä²vªºCODE¤F

TOP

·PÁªO¥D¤À¨É:
³o¬O¤@½g¦n¤å³¹¡A¹ï©óªì¾ÇªÌªº§Ú¦Ó¨¥¦³«Ü¤jªºÀ°§U
ASUS

TOP

        ÀR«ä¦Û¦b : «H¤ß¡B¼Ý¤O¡B«i®ð¤TªÌ¨ã³Æ¡A«h¤Ñ¤U¨S¦³°µ¤£¦¨ªº¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD