网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
09月26日漏签0天
excel吧 关注:281,653贴子:1,553,403
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 38回复贴,共1页
<<返回excel吧
>0< 加载中...

求助[求助]有没有能完成这种排列的功能

  • 只看楼主
  • 收藏

  • 回复
  • 唐僧
  • E见钟情
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
要怎么把图一排成图二这样,把最小的放在左上角然后一次往后排直到最大值在右下角的。图片只是示例,实际上要排40×40的表格



  • QQ47436528
  • 日新月E
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
vba


2025-09-26 10:35:13
广告
不感兴趣
开通SVIP免广告
  • 我撑着油纸伞
  • E览无余
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
以下公式是按你的示例写的,40*40的表格应该就是把乘以3和减3的3换成40,公式向右向下填充。


  • ssg365
  • E夫当关
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
模拟5*5的数据,请根据实际情况调整


  • 爱过小生
  • 日新月E
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
默认你的数据是从a1单元格开始的40*40连续区域

Sub 问题()
Dim arr, brr, minv, minv2, a, b, c
arr = [a1].CurrentRegion
ReDim brr(1 To UBound(arr, 1) * UBound(arr, 2), 1 To 2)
For a = 1 To UBound(arr, 1)
For b = 1 To UBound(arr, 2)
c = c + 1
brr(c, 1) = arr(a, b)
Next
Next
For a = 1 To UBound(brr, 1)
minv = brr(a, 1)
minv2 = brr(a, 1)
For b = a + 1 To UBound(brr, 1)
If brr(b, 1) < minv Then
minv = brr(b, 1)
c = b
End If
Next
If minv < brr(a, 1) Then
brr(a, 1) = brr(c, 1)
brr(c, 1) = minv2
End If
Next
c = 0
For a = 1 To UBound(arr, 1)
For b = 1 To UBound(arr, 2)
c = c + 1
arr(a, b) = brr(c, 1)
Next
Next
c = [a1].End(xlToRight).Column + 2
Cells(1, c).Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End Sub


  • black__殇
  • E览无余
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

=SMALL(A1:J10,SEQUENCE(10,10))
模拟的10*10。
40*40的话,A1:J10改成你实际区域。把SEQUENCE参数改成SEQUENCE(40,40)


  • 爱过小生
  • 日新月E
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
凑合着用吧,用的是cells去排序,原本想做二维数组的选择排序的,但是没法记录行号。
40*40要10秒钟完成,@black__殇,@不会VBA,@QQ47436528。@菠萝蜜
求助其他大佬



Sub 问题()
Dim minv, minv2 As Long
Dim arr, a, b, c, d, rr, bb
f = 1
rr = [a1].End(xlDown).row
bb = [a1].End(xlToRight).Column
For a = 1 To rr
For b = 1 To bb
minv = Cells(a, b).Value
minv2 = Cells(a, b).Value
Cells(a, b).Copy Cells(rr + 1, bb + 1)
For d = a To [a1].End(xlDown).row
For c = f To [a1].End(xlToRight).Column
If Cells(d, c).Value < minv Then
minv = Cells(d, c).Value
col = c
r = d
End If
Next
f = 1
Next
If minv < Cells(a, b).Value Then
Cells(r, col).Copy Cells(a, b)
Cells(rr + 1, bb + 1).Copy Cells(r, col)
End If
f = b + 1
Next
Next
Cells(rr + 1, bb + 1).Clear
End Sub


  • 爱过小生
  • 日新月E
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
系统删贴好烦,我尽力了,我帮你艾特其他大神看看



Sub 问题()
Dim minv, minv2 As Long
Dim arr, a, b, c, d, rr, bb
f = 1
rr = [a1].End(xlDown).row
bb = [a1].End(xlToRight).Column
For a = 1 To rr
For b = 1 To bb
minv = Cells(a, b).Value
minv2 = Cells(a, b).Value
Cells(a, b).Copy Cells(rr + 1, bb + 1)
For d = a To [a1].End(xlDown).row
For c = f To [a1].End(xlToRight).Column
If Cells(d, c).Value < minv Then
minv = Cells(d, c).Value
col = c
r = d
End If
Next
f = 1
Next
If minv < Cells(a, b).Value Then
Cells(r, col).Copy Cells(a, b)
Cells(rr + 1, bb + 1).Copy Cells(r, col)
End If
f = b + 1
Next
Next
Cells(rr + 1, bb + 1).Clear
End Sub


2025-09-26 10:29:13
广告
不感兴趣
开通SVIP免广告
  • 不会VBA
  • E览无余
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
或者试试规划求解


  • 菠萝蜜
  • E览无余
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Option Explicit
Sub abc()
 Dim i, j, m
 Application.ScreenUpdating = False
 For j = 1 To 40
  Cells(1, j).Resize(40).Copy Cells(m + 1, "ap")
  m = m + 40
 Next
 Range("ap1").Resize(1600).Sort [ap1], 1
 Application.ScreenUpdating = True
End Sub


  • 不会VBA
  • E览无余
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
emm,来了来了,就是说,我的水平也就这样的代码了:
Sub SortAndCheckDuplicates()
Application.ScreenUpdating = False ' 禁用屏幕更新
Dim rng As Range
Dim sortedRng As Range
Dim i As Long
Dim j As Long
Dim temp As Variant
Dim cell As Range
Dim duplicates As Collection
' 创建一个集合来存储重复的数值
Set duplicates = New Collection
' 获取选定的区域
Set rng = Selection
' 检查是否有选中区域
If rng Is Nothing Then
MsgBox "请先选中要排序的区域!", vbExclamation
Exit Sub
End If
' 检查区域是否只包含数字
For Each cell In rng
If Not IsNumeric(cell.Value) Then
MsgBox "请选择只包含数字的区域!", vbExclamation
Exit Sub
End If
Next cell
' 排序整个数据区域
Set sortedRng = rng.CurrentRegion
' 使用气泡排序算法对整个数据区域进行排序
For i = 1 To sortedRng.Rows.Count * sortedRng.Columns.Count - 1
For j = 1 To sortedRng.Rows.Count * sortedRng.Columns.Count - i
If sortedRng.Cells(j) > sortedRng.Cells(j + 1) Then
temp = sortedRng.Cells(j).Value
sortedRng.Cells(j).Value = sortedRng.Cells(j + 1).Value
sortedRng.Cells(j + 1).Value = temp
End If
Next j
Next i
' 检查重复的数字
For Each cell In sortedRng
If Application.WorksheetFunction.CountIf(sortedRng, cell.Value) > 1 And Not IsInCollection(cell.Value, duplicates) Then
' 如果有重复的数字,并且尚未添加到集合中,将其添加到集合中
duplicates.Add cell.Value
End If
Next cell
' 显示提示框
If duplicates.Count > 0 Then
Dim dupl As Variant
Dim result As String
' 将集合中的数值添加到结果字符串中
For Each dupl In duplicates
result = result & dupl & ","
Next dupl
result = Left(result, Len(result) - 1)
MsgBox "排序已完成!重复出现的数值有:" & result & "。", vbInformation
Else
MsgBox "排序已完成!没有重复出现的数值。", vbInformation
End If
Application.ScreenUpdating = True ' 重新启用屏幕更新
End Sub
' 检查一个值是否已经存在于集合中
Function IsInCollection(val As Variant, coll As Collection) As Boolean
Dim i As Long
On Error Resume Next
IsInCollection = False
For i = 1 To coll.Count
If coll(i) = val Then
IsInCollection = True
Exit Function
End If
Next i
End Function
处理时间确实有一点长,如果你想看起来很酷,那你可以把禁用屏幕更新和启用屏幕更新的那两段给注释掉。


  • QQ47436528
  • 日新月E
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Sub 企鹅47436528()
Dim i, m, r, x, y, arr, n
arr = [a1].CurrentRegion
x = UBound(arr)
y = UBound(arr, 2)
Columns(y + 2).Resize(, y + 2).Delete
For i = 1 To y
Cells(1, i).Resize(x).Copy Cells(m + 1, y + 2)
m = Cells(Rows.Count, y + 2).End(3).Row
Next
Cells(1, y + 2).Resize(m).Sort Cells(1, y + 2), 1
n = 1
For i = 1 To m Step y
Cells(i, y + 2).Resize(y).Copy
Cells(n, y + 3).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
n = n + 1
Next i
Columns(y + 2).Delete
End Sub


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 38回复贴,共1页
<<返回excel吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示